home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / unixcpio.gz / unixnet.cpio / pmacros.h < prev    next >
Text File  |  1994-07-11  |  6KB  |  394 lines

  1. ;Assembly language macros for C compiler independence.  Assemble with /mx
  2. ;to ensure mixed case symbols.
  3.  
  4.   ifndef MSC
  5. MSC        equ    0
  6.   endif
  7.   ifndef TURBO
  8. TURBO        equ    0
  9.   endif
  10.   ifndef AZTEC
  11. AZTEC        equ    0
  12.   endif
  13.   if MSC + TURBO + AZTEC NE 1
  14.     .err One and only one of MSC, TURBO, and AZTEC should be defined.
  15.   endif
  16.  
  17.  
  18. ;Copyright, 1987, 1988, Russell Nelson
  19. ;Permission to use, copy, modify and distribute this software for any purpose
  20. ;and without fee is hereby granted, provided that the above copyright notice
  21. ;appears in all copies and that both that copyright notice and this permission
  22. ;appear in supporting documentation.  Russell Nelson MAKES NO REPRESENTATIONS
  23. ;ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE.  IT IS PROVIDED
  24. ;"AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
  25.  
  26.     .xlist
  27.  
  28. ;Note that symbols defined by these macros (pubproc, extproc, pubvar, extvar)
  29. ;should be referred by users of this package as 's@' where 's' is the defined
  30. ;symbol.  This hides the compiler's underscore convention.  For example,
  31. ;    include pmacros.h
  32. ;    extproc    foo
  33. ;    pubproc    bar
  34. ;    call    foo@
  35. ;    pend    bar
  36.  
  37. ;begin a public procedure and label it 'a'.  If 'd' is absent, then default
  38. ;to what LARGECODE says, otherwise 'd' must be 'far' or 'near'.
  39. ;Terminated by pend.
  40. pubproc    macro    a, d
  41.   if AZTEC
  42.     assume    cs:_text, ds:dgroup
  43.   endif
  44.   if TURBO
  45.     assume    cs:_text, ds:dgroup
  46.   endif
  47.   if MSC
  48.     assume    cs:_TEXT, ds:DGROUP
  49.   endif
  50.     cseg
  51.   if AZTEC
  52. a&@    equ    a&_
  53.     public    a&_
  54.   else
  55. a&@    equ    _&a
  56.     public    _&a
  57.   endif
  58.   ifb    <d>
  59.   ifdef LARGECODE
  60.   if AZTEC
  61. a&_    proc    far
  62.   else
  63. _&a    proc    far
  64.   endif
  65. first_param    =    6
  66.   else
  67.     if AZTEC
  68. a&_    proc    near
  69.     else
  70. _&a    proc    near
  71.     endif
  72. first_param    =    4
  73.   endif
  74.   else    ;ifb
  75.     if AZTEC
  76. a&_    proc    d
  77.     else
  78. _&a    proc    d
  79.     endif
  80.   ifidn    <d>,<far>
  81. first_param    =    6
  82.   else
  83. first_param    =    4
  84.   endif
  85.   endif
  86.     endm
  87.  
  88. ;used internally to expand first_param and increment it.
  89. _param    macro    a, o, t, n
  90. a    equ    t ptr o[bp]
  91. first_param = first_param + n
  92.     endm
  93.  
  94.  
  95. ;declare a parameter.  Use byte, word, ptr, or fptr (function pointer).
  96. param    macro    a, t
  97.   ifidn <t>,<byte>
  98.     _param    a, %first_param, byte, 2
  99.   endif
  100.   ifidn <t>,<word>
  101.     _param    a, %first_param, word, 2
  102.   endif
  103.   ifidn <t>,<ptr>
  104.   ifdef LARGEDATA
  105.     _param    a, %first_param, dword, 4
  106.   else
  107.     _param    a, %first_param, word, 2
  108.   endif
  109.   endif
  110.   ifidn <t>,<fptr>
  111.   ifdef LARGECODE
  112.     _param    a, %first_param, dword, 4
  113.   else
  114.     _param    a, %first_param, word, 2
  115.   endif
  116.   endif
  117.     endm
  118.  
  119. ;load a data pointer.
  120. ldptr    macro    off_reg,var,seg_reg
  121.   ifdef LARGEDATA
  122.     l&seg_reg    off_reg,var
  123.   else
  124.     mov    off_reg,var
  125.   endif
  126.     endm
  127.  
  128.  
  129. ;define a public procedure with parameters, like so:
  130. ;procdef    foo, <<bar, word>, <baz, ptr>>
  131. ;Terminated by pret, pend
  132. procdef    macro    n, a
  133.     pubproc    n
  134.     irp    one_param, <a>
  135.     param    one_param
  136.     endm
  137.     push    bp
  138.     mov    bp,sp
  139.     endm
  140.  
  141. ;return from a procedure with parameters.  Pairs with procdef
  142. pret    macro
  143.     pop    bp
  144.     ret
  145.     endm
  146.  
  147. ;end a public procedure.  Pairs with pubproc
  148. pend    macro    a
  149.   if AZTEC
  150. a&_    endp
  151.   else
  152. _&a    endp
  153.   endif
  154.     csegend
  155.     endm
  156.  
  157. ;define an external procedure called 'a'.  If 'd' is absent, then default
  158. ;to what LARGECODE says, otherwise 'd' must be 'far' or 'near'.
  159.  
  160. extproc    macro    a, d
  161.   ifb    <d>
  162.   ifdef LARGECODE
  163.     if AZTEC
  164.     extrn    a&_: far
  165.     else
  166.     extrn    _&a: far
  167.     endif
  168.   else
  169.     if AZTEC
  170.     extrn    a&_: near
  171.     else
  172.     extrn    _&a: near
  173.     endif
  174.   endif
  175.   else    ;ifb
  176.     if AZTEC
  177.     extrn    a&_: d
  178.     else
  179.     extrn    _&a: d
  180.     endif
  181.   endif
  182.   if AZTEC
  183. a&@    equ    a&_
  184.   else
  185. a&@    equ    _&a
  186.   endif
  187.     endm
  188.  
  189. ;open the code segment
  190. cseg    macro
  191.   if AZTEC
  192. codeseg    segment byte public 'code'
  193.     assume    cs:code, ds:dataseg
  194.   endif
  195.   if TURBO
  196. _TEXT    segment byte public 'CODE'
  197. dgroup    group    _DATA,_BSS
  198.     assume    cs:_TEXT, ds:dgroup
  199.   endif
  200.   if MSC
  201. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  202. DGROUP    GROUP    CONST,    _BSS,    _DATA
  203.     assume    cs:_TEXT, ds:DGROUP
  204.   endif
  205.     endm
  206.  
  207. ;close the code segment
  208. csegend    macro
  209.   if AZTEC
  210. codeseg    ends
  211.   endif
  212.   if TURBO or MSC
  213. _TEXT    ends
  214.   endif
  215.     endm
  216.  
  217. ;assume that the ds is the code segment
  218. dscode    macro
  219.   if AZTEC
  220.     assume    ds:codeseg
  221.   endif
  222.   if TURBO or MSC
  223.     assume    ds:_TEXT
  224.   endif
  225.     endm
  226.  
  227.  
  228. ;Return the data segment
  229. getds    macro
  230.   if AZTEC
  231.     mov    ax,dataseg
  232.   endif
  233.   if TURBO
  234.     mov    ax,dgroup
  235.   endif
  236.   if MSC
  237.     mov    ax,DGROUP
  238.   endif
  239.     endm
  240.  
  241.  
  242. ;open the data segment
  243. dseg    macro
  244.   if AZTEC
  245. dataseg    segment word public 'data'
  246.   endif
  247.   if TURBO or MSC
  248. _DATA    segment word public 'DATA'
  249.   endif
  250.     endm
  251.  
  252. ;close the data segment
  253. dsegend    macro
  254.   if AZTEC
  255. dataseg    ends
  256.   endif
  257.   if TURBO or MSC
  258. _DATA    ends
  259.   endif
  260.     endm
  261.  
  262. ;open the uninitialized data segment
  263. bseg    macro
  264.   if AZTEC
  265. bssseg    segment word public 'data'
  266.   endif
  267.   if TURBO
  268. _BSS    segment word public 'DATA'
  269.   endif
  270.   if MSC
  271. _BSS    segment word public 'BSS'
  272.   endif
  273.     endm
  274.  
  275. ;close the uninitialized data segment
  276. bsegend    macro
  277.   if AZTEC
  278. bssseg    ends
  279.   endif
  280.   if TURBO or MSC
  281. _BSS    ends
  282.   endif
  283.     endm
  284.  
  285. ;define a public variable
  286. ;use it like so: pubvar a,<dw 0>
  287. pubvar    macro    n,d
  288.   if AZTEC
  289.     public    n
  290. n&@    equ    n
  291. n    d
  292.   endif
  293.   if TURBO or MSC
  294.     public    _&n
  295. n&@    equ    _&n
  296. _&n    d
  297.   endif
  298.     endm
  299.  
  300. ;define an external variable
  301. ;use it like so: extvar a,word
  302. ; or extvar a,byte
  303. extvar    macro    n,d
  304.   if AZTEC
  305. n&@    equ    n&_
  306.     extrn    n&_: d
  307.   endif
  308.   if TURBO or MSC
  309. n&@    equ    _&n
  310.     extrn    _&n: d
  311.   endif
  312.     endm
  313.  
  314. ; Conditional DS save/restore macros
  315. pushds    macro
  316.   ifdef LARGEDATA
  317.     push    ds
  318.   endif
  319.     endm
  320.  
  321. popds    macro
  322.   ifdef LARGEDATA
  323.     pop    ds
  324.   endif
  325.     endm
  326.  
  327. ; Conditional ES save/restore macros
  328. pushes    macro
  329.   ifdef LARGEDATA
  330.     push    es
  331.   endif
  332.     endm
  333.  
  334. popes    macro
  335.   ifdef LARGEDATA
  336.     pop    es
  337.   endif
  338.     endm
  339.  
  340. ;define the segments so that they exist.
  341. dseg
  342. dsegend
  343. bseg
  344. bsegend
  345. cseg
  346. csegend
  347.  
  348. ;define an interrupt handler.
  349. inthandler    macro    xxxname, xxxnum
  350.  
  351.     dseg
  352.     extvar    sssave,word
  353.     extvar    spsave,word
  354.     extvar    intstk,byte
  355.     dsegend
  356.  
  357.     extproc    doret
  358.     extproc    xxxname&int
  359.  
  360.     pubproc    xxxname&xxxnum&vec
  361.  
  362.     push    ax        ; save ax first.
  363.     push    ds        ; save on user stack
  364.     getds
  365.     mov    ds,ax
  366.  
  367.     mov    sssave@,ss    ; stash user stack context
  368.     mov    spsave@,sp
  369.  
  370.     mov    ss,ax        ; set up interrupt stack
  371.     lea    sp,intstk@
  372.  
  373.     push    bx        ; save user regs on interrupt stack
  374.     push    cx
  375.     push    dx
  376.     push    bp
  377.     push    si
  378.     push    di
  379.     push    es
  380.  
  381.     push    ds
  382.     pop    es
  383.  
  384.     mov    ax,xxxnum    ; arg for service routine
  385.     push    ax
  386.     call    xxxname&int@
  387.     pop    ax
  388.     jmp    doret@
  389.     pend    xxxname&xxxnum&vec
  390.  
  391.     endm
  392.  
  393.     .list
  394.